#include "score.h"

Score* Score::ptr = NULL;

Score::Score (Champions g[3])
{
	ptr = this;
	for (int i = 0; i < 3; i ++)
		gamer[i] = g[i];
}

BOOL CALLBACK Score::DlgProc(HWND hWnd, UINT mes, WPARAM wParam, LPARAM lParam)
{
	switch(mes)
	{
		HANDLE_MSG(hWnd,WM_INITDIALOG,ptr->Cls_OnInitDialog);
		HANDLE_MSG(hWnd,WM_CLOSE,ptr->Cls_OnClose);
		HANDLE_MSG(hWnd,WM_COMMAND,ptr->Cls_OnCommand);
	}
	return FALSE;
}

BOOL Score::Cls_OnInitDialog (HWND hWnd, HWND hWndFocus, LPARAM lParam)
{
	HWND hName[3];
	HWND hSteps[3];
	HWND hTime[3];
	TCHAR str1[5];
	for (int i = 0; i < 9; i ++)
	{
		if (i < 3)
		{
			hName[i] = GetDlgItem(hWnd, IDC_STATIC1+i);
			SetWindowText(hName[i], gamer[i].name);
		}
		if (i > 2 && i < 6)
		{
			hSteps[i%3] = GetDlgItem(hWnd, IDC_STATIC1+i);
			_itot(gamer[i%3].steps, str1, 10);
			SetWindowText(hSteps[i%3], str1);
		}
		if (i > 5)
		{
			hTime[i%3] = GetDlgItem(hWnd, IDC_STATIC1+i);
			_itot(gamer[i%3].time, str1, 10);
			SetWindowText(hTime[i%3], str1);
		}
	}

	
	/*HANDLE hFile = CreateFile(TEXT("scores.txt"),GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
      FILE_ATTRIBUTE_NORMAL, 0);

	TCHAR ReadBuffer[200] = {0};
	DWORD  dwBytesRead1 = 0;
	ReadFile(hFile, ReadBuffer, 199, &dwBytesRead1, NULL);

	int index = 0;
	int index2 = 0;
	TCHAR* str = new TCHAR[20];
	lstrcpy(str, TEXT(""));
	for (int i = 0; i < lstrlen(ReadBuffer); i++)
	{
		if (ReadBuffer[i] == '&')
		{
			memmove(str, ReadBuffer+index2, sizeof(ReadBuffer[0])*(i-index2));
			str[i-index2] = '\0';
			if (index%3 == 0)
				SetWindowText(hName[index/3], str);
			else if (index%3 == 1)
				SetWindowText(hSteps[index/3], str);
			else if (index%3 == 2)
				SetWindowText(hTime[index/3], str);
			lstrcpy (str, TEXT(""));
			index ++;
			index2 = i + 1;
		}
	}*/


	return TRUE;
}

void Score::Cls_OnClose (HWND hWnd)
{
	EndDialog(hWnd, 0);
}

void Score::Cls_OnCommand (HWND hWnd, int id, HWND hWndCtl, UINT codeNotify)
{
}